package br.com.escolaespacocrianca.fineec.business;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.com.caelum.vraptor.ioc.Component;
import br.com.escolaespacocrianca.fineec.model.Plot;

@Component
public class PlotPaymentBusiness {
	
	private final Session session;
	
	public PlotPaymentBusiness(Session session) {
		this.session = session;
	}
	
	@SuppressWarnings("unchecked")
	public List<Plot> list() {

		return session.createCriteria( Plot.class).list();
	}

	public void save(Plot t) {
		session.beginTransaction();
		session.saveOrUpdate(t);
		session.getTransaction().commit();
	}

	public Plot find(Integer id) {

		return (Plot) session.createCriteria(Plot.class)
				.add(Restrictions.eq("id", id)).uniqueResult();
	}
	
	public void delete(Plot t) {
		session.beginTransaction();
		
		session.delete(t);
		
		session.getTransaction().commit();
	}

}
